/*
 * =====================================================================================
 *
 *       Filename:  parlindrome.cpp
 *
 *    Description:  parlindrome
 *
 *        Version:  1.0
 *        Created:  01/04/2014 18:30:20
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include <iostream>
#include <string>

using namespace std;

inline void expand(const string &input, int &s, int &e)
{
    int len = input.length();
    while(s>=0 && e<len && input[s]==input[e]){
        s--;
        e++;
    }

    s ++;
    e --;
}

const string longest_parlindrome(const string &input)
{
    int ss, ee; 
    int len = input.length();
    int longest = 0;
    for (int i=0; i<len; i++)
    {
        int li, ri, n;
        li = ri = i;
        expand( input, li, ri );
        n = ri-li+1;
        if( n > longest){
           ss = li;
           ee = li;
           longest = n;
        }
       

        li = i;
        ri = i+1;
        expand( input, li, ri );
        n = ri-li+1;
        if( n > longest){
           ss = li;
           ee = li;
           longest = n;
        }
    }
    
    return input.substr(ss, longest);
}

int main(){

    string input="123abcdcb671";

    cout << longest_parlindrome( input ) <<endl;

}

